<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>声明周期函数（钩子）</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
  <div id="app">
    <h1>
      {{title}}
    </h1>
  </div>
  <script>
    var app = new Vue({
      el: '#app',
      data: {
        title: 'hello vue'
      },

      // 声明周期函数
      beforeCreate() {
        // console.log(this.title)
      },

      created() {
        // console.log(this.title)
        // console.log(document.querySelector('h1').innerHTML)
        // this.title = 'hello world'
      },

      beforeMount() {
        // console.log(document.querySelector('h1').innerHTML)
      },

      mounted() {
        // console.log(document.querySelector('h1').innerHTML)
        // setTimeout((params) => {
        //   this.title = 'hello vue !!!!'
        // }, 2000)

        // console.log('mounted.')

        this.title = 'hello vue !!!!'

        // setInterval((params) => {
        //   this.title = new Date().getTime()
        // }, 1000)
      },

      beforeUpdate() {
        console.log(document.querySelector('h1').innerHTML)
      },

      updated() {
        console.log(document.querySelector('h1').innerHTML)
        // this.title = new Date().getTime()
      },

      beforeDestroy() {
        console.log('beforeDestory')
      },

      destroyed() {
        console.log('destroyed')
      },
    })

    // app.$mount('#app')
    setTimeout((params) => {
      app.$destroy()
    }, 5000)
  </script>
</body>
</html>